package org.kongcloud.core.upload.fast;

import java.util.Comparator;

public class StringComparator implements Comparator<String> {
    public String getPackageSuffix() {
        return packageSuffix;
    }

    public void setPackageSuffix(String packageSuffix) {
        this.packageSuffix = packageSuffix;
    }

    private String packageSuffix;


    @Override
    public int compare(String o1, String o2) {
        String tag = "." + getPackageSuffix() +
                ".";
        int pos1 = o1.indexOf(tag);
        int pos2 = o2.indexOf(tag);
        int index1 = Integer.parseInt(o1.substring(pos1 + tag.length()).replace(".part", ""));
        int index2 = Integer.parseInt(o2.substring(pos2 + tag.length()).replace(".part", ""));
        return index1 - index2;
    }
}